package com.car.controller;

import com.car.entity.Emp;
import com.car.entity.Yeji;
import com.car.entity.YejiParameter;
import com.car.service.IYejiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Description:
 * @author: hsy
 * @version: v1.0
 * @Date
 */
@Controller
public class YejiController {
    @Autowired
    @Qualifier("yejiService")
    private IYejiService iYejiService;

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public String findChuzhiAll(Model model, YejiParameter yejiParameter, HttpSession session){
        System.out.println(yejiParameter.toString());
        Integer eid = yejiParameter.getEid();
        System.out.println(eid);
        model.addAttribute("eid",eid);

        //查找工种
        String job = iYejiService.findJob(yejiParameter);
        model.addAttribute("job",job);
        //储值卡提成
        Yeji chuzhiTicheng = iYejiService.findChuzhiTicheng(yejiParameter);
        int zticheng = chuzhiTicheng.getZticheng();

        model.addAttribute("chuzhiTicheng",chuzhiTicheng);
        System.out.println("chuzhiTicheng"+zticheng);
        //年卡提成
        Yeji niankaTicheng = iYejiService.findNiankaTicheng(yejiParameter);
        int zticheng1 = niankaTicheng.getZticheng();
        model.addAttribute("niankaTicheng",niankaTicheng);
        System.out.println("niankaTicheng"+zticheng1);
        //销售提成
        Yeji xiaoshouTicheng = iYejiService.findXiaoshouTicheng(yejiParameter);
        int zticheng2 = xiaoshouTicheng.getZticheng();
        System.out.println("findXiaoshouTicheng"+zticheng2);
        model.addAttribute("xiaoshouTicheng",xiaoshouTicheng);
        //施工提成
        Yeji shigongTicheng = iYejiService.findShigongTicheng(yejiParameter);
        int zticheng3 = shigongTicheng.getZticheng();
        System.out.println("shigongTicheng"+zticheng3);
        model.addAttribute("shigongTicheng",shigongTicheng);
        //总提成
        int ztc =zticheng+zticheng1+zticheng2+zticheng3;
        model.addAttribute("ztc",ztc);

        System.out.println(ztc+"-----------------------------------------------");

        //查找储值卡
        List<Yeji> chuzhi = iYejiService.findChuzhiAll(yejiParameter);
        model.addAttribute("chuzhi",chuzhi);
        //查找年卡
        List<Yeji> nianka = iYejiService.findNiankaAll(yejiParameter);
        model.addAttribute("nianka",nianka);
        //查找施工
        List<Yeji> shigong = iYejiService.findShigongAll(yejiParameter);
        if(job.equals("5")){
            model.addAttribute("shigong",shigong);
        }
        //查找销售
        List<Yeji> xiaoshou = iYejiService.findXiaoshouAll(yejiParameter);
        System.out.println("销售"+xiaoshou);
        session.setAttribute("xiaoshou",xiaoshou);
        if(job.equals("4")){
            model.addAttribute("xiaoshou",xiaoshou);
        }
        //查找姓名
        Emp name = iYejiService.findName(eid);
        model.addAttribute("name",name);
        return "/staff_Achievement.jsp";
    }
}
